import { LayerInfoType } from "@/types";

interface TransformedItem {
  key: string;
  label: string;
}

//将英文的数据转换成中文，并且用于展示在地图上面
export function renderDataToZhOnMapInfo(
  data: LayerInfoType
): TransformedItem[] {
  // 字段映射表：英文key → 中文key
  const keyMap: Record<string, string> = {
    name: "名称",
    address: "地址",
    evaluationTitle: "建议标题",
    evaluationContent: "建议内容",
    evaluator: "建议人",
    rectificationType: "建议来源",
    projectType: "项目类型",
    issueType: "问题类型",
    issueTitle: "问题标题",
    issueDescription: "问题描述",
  };

  const transformed: TransformedItem[] = [];

  // 遍历需要转换的字段
  Object.keys(keyMap).forEach((englishKey) => {
    const chineseKey = keyMap[englishKey];
    // 检查数据中是否存在该字段（避免undefined）
    if (
      Object.prototype.hasOwnProperty.call(data, englishKey) &&
      data[englishKey as keyof LayerInfoType] !== undefined &&
      data[englishKey as keyof LayerInfoType] !== null
    ) {
      transformed.push({
        key: chineseKey,
        label: String(data[englishKey as keyof LayerInfoType]), // 转换为字符串统一处理
      });
    }
  });

  return transformed;
}
